﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class cungcapDAL:VO.ketnoi
    {
        public List<VO.cungcapVO> cungcap_xem()
        {
            List<VO.cungcapVO> list = new List<VO.cungcapVO>();
            using (SqlCommand dbCmd = new SqlCommand("cungcap_xem", GetConnection()))
            {
                VO.cungcapVO obj = new VO.cungcapVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.cungcapIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool cungcap_them(VO.cungcapVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("cungcap_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@gia", data.Gia));
                    dbCmd.Parameters.Add(new SqlParameter("@mamh", data.MaMh));
                    dbCmd.Parameters.Add(new SqlParameter("@mancc", data.MaNcc));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool cungcap_sua(VO.cungcapVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("cungcap_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@mamh", data.MaMh));
                dbCmd.Parameters.Add(new SqlParameter("@mancc", data.MaNcc));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool cungcap_xoa(string mamh)
        {
            using (SqlCommand dbCmd = new SqlCommand("cungcap_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@mamh", mamh));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
